home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / states / AddChild.as next >
Text File  |  2009-02-12  |  6KB  |  187 lines

  1. package mx.states
  2. {
  3.    import flash.display.DisplayObject;
  4.    import mx.containers.ApplicationControlBar;
  5.    import mx.containers.ControlBar;
  6.    import mx.containers.Panel;
  7.    import mx.core.Application;
  8.    import mx.core.ContainerCreationPolicy;
  9.    import mx.core.IDeferredInstance;
  10.    import mx.core.UIComponent;
  11.    import mx.core.mx_internal;
  12.    import mx.resources.IResourceManager;
  13.    import mx.resources.ResourceManager;
  14.    
  15.    use namespace mx_internal;
  16.    
  17.    public class AddChild implements IOverride
  18.    {
  19.       
  20.       mx_internal static const VERSION:String = "3.0.0.0";
  21.        
  22.       
  23.       mx_internal var added:Boolean = false;
  24.       
  25.       mx_internal var instanceCreated:Boolean = false;
  26.       
  27.       private var _creationPolicy:String = "auto";
  28.       
  29.       public var relativeTo:UIComponent;
  30.       
  31.       public var position:String;
  32.       
  33.       private var _target:DisplayObject;
  34.       
  35.       private var _targetFactory:IDeferredInstance;
  36.       
  37.       private var resourceManager:IResourceManager;
  38.       
  39.       public function AddChild(param1:UIComponent = null, param2:DisplayObject = null, param3:String = "lastChild")
  40.       {
  41.          resourceManager = ResourceManager.getInstance();
  42.          super();
  43.          this.relativeTo = param1;
  44.          this.target = param2;
  45.          this.position = param3;
  46.       }
  47.       
  48.       public function remove(param1:UIComponent) : void
  49.       {
  50.          var _loc2_:UIComponent = !!relativeTo ? relativeTo : param1;
  51.          if(!mx_internal::added)
  52.          {
  53.             return;
  54.          }
  55.          switch(position)
  56.          {
  57.             case "before":
  58.             case "after":
  59.                _loc2_.parent.removeChild(target);
  60.                break;
  61.             case "firstChild":
  62.             case "lastChild":
  63.             default:
  64.                if(target is ControlBar && _loc2_ is Panel)
  65.                {
  66.                   Panel(_loc2_).rawChildren.removeChild(target);
  67.                   Panel(_loc2_).createComponentsFromDescriptors();
  68.                }
  69.                else if(target is ApplicationControlBar && ApplicationControlBar(target).dock)
  70.                {
  71.                   Application(_loc2_).dockControlBar(ApplicationControlBar(target),false);
  72.                   Application(_loc2_).removeChild(target);
  73.                }
  74.                else if(_loc2_ == target.parent)
  75.                {
  76.                   _loc2_.removeChild(target);
  77.                }
  78.          }
  79.          added = false;
  80.       }
  81.       
  82.       public function initialize() : void
  83.       {
  84.          if(creationPolicy == ContainerCreationPolicy.AUTO)
  85.          {
  86.             createInstance();
  87.          }
  88.       }
  89.       
  90.       public function get target() : DisplayObject
  91.       {
  92.          if(!_target && creationPolicy != ContainerCreationPolicy.NONE)
  93.          {
  94.             createInstance();
  95.          }
  96.          return _target;
  97.       }
  98.       
  99.       public function set creationPolicy(param1:String) : void
  100.       {
  101.          _creationPolicy = param1;
  102.          if(_creationPolicy == ContainerCreationPolicy.ALL)
  103.          {
  104.             createInstance();
  105.          }
  106.       }
  107.       
  108.       public function set target(param1:DisplayObject) : void
  109.       {
  110.          _target = param1;
  111.       }
  112.       
  113.       public function apply(param1:UIComponent) : void
  114.       {
  115.          var _loc3_:String = null;
  116.          var _loc2_:UIComponent = !!relativeTo ? relativeTo : param1;
  117.          added = false;
  118.          if(!target)
  119.          {
  120.             return;
  121.          }
  122.          if(target.parent)
  123.          {
  124.             _loc3_ = resourceManager.getString("states","alreadyParented");
  125.             throw new Error(_loc3_);
  126.          }
  127.          switch(position)
  128.          {
  129.             case "before":
  130.                _loc2_.parent.addChildAt(target,_loc2_.parent.getChildIndex(_loc2_));
  131.                break;
  132.             case "after":
  133.                _loc2_.parent.addChildAt(target,_loc2_.parent.getChildIndex(_loc2_) + 1);
  134.                break;
  135.             case "firstChild":
  136.                _loc2_.addChildAt(target,0);
  137.                break;
  138.             case "lastChild":
  139.             default:
  140.                _loc2_.addChild(target);
  141.                if(target is ControlBar && _loc2_ is Panel)
  142.                {
  143.                   Panel(_loc2_).createComponentsFromDescriptors();
  144.                }
  145.                else if(target is ApplicationControlBar && ApplicationControlBar(target).dock && _loc2_ is Application)
  146.                {
  147.                   ApplicationControlBar(target).resetDock(true);
  148.                }
  149.          }
  150.          added = true;
  151.       }
  152.       
  153.       public function createInstance() : void
  154.       {
  155.          var _loc1_:Object = null;
  156.          if(!mx_internal::instanceCreated && !_target && targetFactory)
  157.          {
  158.             instanceCreated = true;
  159.             _loc1_ = targetFactory.getInstance();
  160.             if(_loc1_ is DisplayObject)
  161.             {
  162.                _target = DisplayObject(_loc1_);
  163.             }
  164.          }
  165.       }
  166.       
  167.       public function set targetFactory(param1:IDeferredInstance) : void
  168.       {
  169.          _targetFactory = param1;
  170.          if(creationPolicy == ContainerCreationPolicy.ALL)
  171.          {
  172.             createInstance();
  173.          }
  174.       }
  175.       
  176.       public function get creationPolicy() : String
  177.       {
  178.          return _creationPolicy;
  179.       }
  180.       
  181.       public function get targetFactory() : IDeferredInstance
  182.       {
  183.          return _targetFactory;
  184.       }
  185.    }
  186. }
  187.